/**
 * 后台功能
 * */


(function () {
})();


//分类跳转
function toTypeUrl(v){
    var url = 'cate.html', tname = '';
    url += '?type=' + v;
    if (v == 1) { tname = '医护类型'; }
    if (v == 2) { tname = '医护头衔'; }
    if (v == 3) { tname = '医院科室'; }
    if (v == 4) { tname = '医护咨询类型'; }
    if (v == 5) { tname = '帖子分类'; }
    if (v == 6) { tname = '代办服务'; }
    if (v == 7) { tname = '号别类型'; }
    if (v == 8) { tname = '小区医护分类'; }
    url += '&tname=' + escape(tname);
    location.href = url;
}


//花钱配置列表
function getConfig(){
    $.ajax({
        type: apis.configIndex.method,
        url: apis.configIndex.url,
        data: { id: id },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            var d = res.data;
            var h = '', i;
            //<div class="row cl">
            //    <label class="form-label col-xs-4 col-sm-3">
            //        <span class="c-red">*</span> 分类名称：
            //    </label>
            //    <div class="formControls col-xs-8 col-sm-9">
            //        <input type="text" class="input-text" id="title"/>
            //    </div>
            //</div>
            for (i = 0; i < d.length; i ++) {
                h += '<div class="row cl">';
                h += '<label class="form-label col-xs-4 col-sm-3">';
                h += d[i].title + '：';
                h += '</label>';
                h += '<div class="formControls col-xs-8 col-sm-9">';
                h += '<input type="text" class="input-text" id="val' + d[i].id + '" value="' + d[i].val + '" style="width: 80%;"/>';
                h += '<div style="padding: 4px 0; width: 20%; background: #0088cc; color: #eee; text-align: center; cursor: pointer; float: right;" onclick="modify(' + d[i].id + ');">保存该配置</div>';
                h += '</div>';
                h += '</div>';
            }
            $('#keylist').html(h);
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


function modify(v){
    var val = $('#val' + v).val();
    if (!val) {
        msgPop({msg: '参数必须的'});
        return
    }
    $.ajax({
        type: apis.configModify.method,
        url: apis.configModify.url,
        data: { id: v, val: val },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '修改成功'});
            setTimeout(function () {
                top.location.href = '';
            }, 1000);
        },
        error: function () {
            console.log('错误辣');
        }
    });
}